<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StackTrace
 *
 * @author hodek
 */
class StackTrace {

    private static $stack = null;

    function StackTrace() {
        
    }

    function __toString() {
        $ret = "";
        $current = $this->stack;
        $ret .= $current;
        while ($current->getPrevious() != null) {
            $current = $current->getPrevious();
            $ret .= $current;
        }
        return $ret;
    }

    public function chain($methodName, $par1 = null, $par2 = null, $par3 = null, $par4 = null, $par5 = null, $par6 = null) {
        $last = null;
        if (isset($this->stack)){
            $last = $this->stack;
        }
        $current = new StackItem($methodName, $last, $par1, $par2, $par3, $par4, $par5, $par6);        
        if ($last != null) $last->setNext($current);
        $this->stack = $current;
    }

}

class StackItem {

    private $methodName = null;
    private $par1 = null;
    private $par2 = null;
    private $par3 = null;
    private $par4 = null;
    private $par5 = null;
    private $par6 = null;
    private $next = null;
    private $previous = null;
    private $date = null;

    function StackItem($methodName, $previous, $par1 = null, $par2 = null, $par3 = null, $par4 = null, $par5 = null, $par6 = null) {
        $this->methodName = $methodName;
        $this->previous = $previous;
        $this->par1 = $par1;
        $this->par2 = $par2;
        $this->par3 = $par3;
        $this->par4 = $par4;
        $this->par5 = $par5;
        $this->par6 = $par6;
        $this->date = microtime();
    }

    public function setNext($stack) {
        $this->next = $stack;
    }

    public function getPrevious() {
        return $this->previous;
    }

    public function __toString() {
        $ret = $this->methodName . "(";
        if ($this->par1 != null) {
           $ret .= $this->par1 . " ,";
        }
        if ($this->par2 != null) {
            $ret .= $this->par2 . " ,";
        }
        if ($this->par3 != null) {
            $ret .= $this->par3 . " ,";
        }
        if ($this->par4 != null) {
            $ret .= $this->par4 . " ,";
        }
        if ($this->par5 != null) {
            $ret .= $this->par5 . " ,";
        }
        if ($this->par6 != null) {
            $ret .= $this->par6 . " ,";
        }
        $ret = substr($ret, 0, -2);
        $ret .= ")";
        //strlen($ret)
        $ret .= " - ".$this->date."\n";
        return $ret;
    }

}

?>
